package customer.zspt.cn.customer.components.tag;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;

import customer.zspt.cn.customer.Adapter.GroupViewAdapter;
import customer.zspt.cn.customer.R;
import customer.zspt.cn.customer.constant.constant;
import customer.zspt.cn.customer.bean.SkillInfoDao;
import customer.zspt.cn.customer.utils.GetAllInfoUtils;
import customer.zspt.cn.customer.utils.SPUtils;

/**
 * Created by Administrator on 2018/6/18 0018.
 */

public class tag_view extends Activity {
    private TextView group_title;
    private TextView user_number;
    private String skillTitle;
    private String title;
    private GridView kfLs;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tag_view);
        initUI();
        int skillId = getIntent().getIntExtra("skillId",1);
        String token = SPUtils.getString(this,"token","");
        GetAllInfoUtils.infoUtils.getFriendInfo(constant.GROUPURL+skillId,token,this);
        GetAllInfoUtils.infoUtils.monitoringLinster(new GetAllInfoUtils.ReadyData() {
            @Override
            public void success(final String data) {
                System.out.println(data);
                  runOnUiThread(new Runnable() {
                      @Override
                      public void run() {
                         ToPull(data);
                      }
                  });
            }
            @Override
            public void fail() {

            }
        });
    }

    private void initUI() {
        group_title = findViewById(R.id.group_title);
        user_number = findViewById(R.id.user_number);
        kfLs = (GridView) findViewById(R.id.kfLs);
    }

    public void ToPull(String data)
    {
        Gson gson = new Gson();
        try{
            SkillInfoDao skillInfoDao = gson.fromJson(data, SkillInfoDao.class);
            skillTitle = skillInfoDao.data.skillTitle;
            int count = skillInfoDao.data.kefus.size();
            group_title.setText(skillTitle);
            user_number.setText(user_number.getText().toString()+count+"");
            GroupViewAdapter adapter = new GroupViewAdapter(this,skillInfoDao);
            kfLs.setAdapter(adapter);
        }
        catch (Exception e)
        {
            Toast.makeText(this,"程序异常",Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }
    }




}
